package com.ruoyi.schedule.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.schedule.domain.Shift;
import com.ruoyi.schedule.service.IShiftService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 班次信息Controller
 */
@RestController
@RequestMapping("/schedule/shift")
public class ShiftController extends BaseController {
    @Autowired
    private IShiftService shiftService;

    /**
     * 查询班次列表
     */
    @PreAuthorize("@ss.hasPermi('schedule:shift:list')")
    @GetMapping("/list")
    public TableDataInfo list(Shift shift) {
        startPage();
        List<Shift> list = shiftService.selectShiftList(shift);
        return getDataTable(list);
    }

    /**
     * 新增班次
     */
    @PreAuthorize("@ss.hasPermi('schedule:shift:add')")
    @Log(title = "班次", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Shift shift) {
        return toAjax(shiftService.insertShift(shift));
    }

    /**
     * 修改班次
     */
    @PreAuthorize("@ss.hasPermi('schedule:shift:edit')")
    @Log(title = "班次", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Shift shift) {
        return toAjax(shiftService.updateShift(shift));
    }

    /**
     * 删除班次
     */
    @PreAuthorize("@ss.hasPermi('schedule:shift:remove')")
    @Log(title = "班次", businessType = BusinessType.DELETE)
    @DeleteMapping("/{shiftIds}")
    public AjaxResult remove(@PathVariable Long[] shiftIds) {
        return toAjax(shiftService.deleteShiftByIds(shiftIds));
    }
}